<style lang="less">
  @import 'Score.less';
</style>
<template>
  <div class="score_container">
    <div class="score_header">
      <div class="score_circle">
        <span>{{score}}</span>
      </div>
    </div>
    <Card title="积分消费详情" icon="ios-options" :padding="10" shadow>
      <CellGroup v-for="(item,index) in detail" :key="index">
        <Cell :title="item.purpose" :label="`时间: ${item.time}`">
          <Badge overflow-count="10000000000" :count="item.type==1 ?`+ ${item.count}`:`- ${item.count}`" slot="extra"/>
        </Cell>
      </CellGroup>
    </Card>
  </div>
</template>

<script>
  import {getScore, updateScore, getScoreList} from '@/api/score';
  import {getCurrentOrganization} from '@/api/organization';
  import {mapGetters} from 'vuex';
  export default {
    name: 'Score',
    data() {
      return {
        detail: [],
        score: 0
      }
    },
    mounted() {
      this.queryList();
      this.queryUser();
    },
    methods: {
      queryList: function () {
        getScoreList().then(res => {
          this.detail = res.data;
        });
      },
      queryUser() {
        getCurrentOrganization(this.userId).then(res=>{
          if (res.data) {
            this.score = res.data.score;
          }else {
            this.$Message.error(res.error);
          }
        })
      },
      btnSaveClick: function () {
        updateScore(this.formItem.id, this.formItem).then(res => {
          if (res.data && res.data.affectedRows > 0) {
            this.$Message.success('保存成功!');
            this.queryList();
          } else {
            this.$Message.error(res.error);
          }
        });
      },
    },
    computed:{
      ...mapGetters(['userId']),
    }
  }

</script>
